<template>
	<div class="contents">
		<van-cell-group>
			<van-field v-model="oldpassword" center clearable label="旧密码" placeholder="请输入原密码" type="password"></van-field>

			<van-field v-model="newpassword" center clearable label="新密码" placeholder="请输入新密码" type="password"></van-field>
			<van-field v-model="renewpassword" @blur="checkpwd" center clearable label="新密码" placeholder="请再次输入新密码" type="password"></van-field>
		</van-cell-group>
		<div class="button-sub">
			<van-button type="primary" block color="#FE7700" round @click="changepwd">提交</van-button>
		</div>

	</div>
</template>

<script>
	export default {
		name: "Password",
		components: {

		},
		data() {
			return {
				oldpassword: "",
				newpassword: '',
				renewpassword: '',
				userInfo: {},
				isSet: false
			}
		},
		mounted() {
			this.userInfo = JSON.parse(this.$getcookie("userInfo"))
		},
		methods: {
			changepwd() {
				let pwdData = {
					user_id: this.userInfo.user_id,
					token: this.$getcookie("jy_token"),
					oldpassword: this.oldpassword,
					newpassword: this.newpassword
				}
				if (this.isSet) {
					this.$api.my.resetpwds(pwdData).then(res => {
						if (res.code == 1) {
							this.$toast.success(res.msg)
							this.$router.go(-1)
						}else{
							this.$toast(res.msg)
						}
					})
				}else{
					this.$toast("两次密码不一致，请重新输入！")
				}

			},
			checkpwd() {
				if (this.renewpassword != this.newpassword) {
					this.$toast("两次密码不一致，请重新输入！")
					this.isSet = false
				} else {
					this.isSet = true
				}
			}
		}


	}
</script>

<style lang="less">
	.contents {
		margin-top: 0.59rem;

		.van-field__label {
			font-size: 0.88rem;
			font-family: PingFang SC;
			font-weight: 500;
			color: rgba(0, 0, 0, 1);
			width: auto;
			margin-right: 0.84rem;
		}

		.van-field__control {
			font-size: 0.81rem;
			font-family: PingFang SC;
			font-weight: 500;
			color: #000;
		}

		.van-field__control::-webkit-input-placeholder {
			font-size: 0.81rem;
			font-family: PingFang SC;
			font-weight: 500;
			color: #A5A5A5;
		}

		.button-sub {
			width: 16.56rem;
			margin: 3.28rem auto;
		}

		.van-button {
			height: 3.06rem;
			font-size: 0.94rem;
			font-family: PingFang SC;
			font-weight: 500;
			color: rgba(255, 255, 255, 1);
			line-height: 3.06rem;
		}


	}
</style>
